package com.cp.yn

import get
import put
import spUtils

object UserManager {

    var channel = "test"

    private var userId: String? = ""

    private var token: String? = ""

    fun setUserId(userId: String? = "") {
        this.userId = userId
        spUtils.put("userId", userId)
    }

    fun setToken(token: String? = "") {
        this.token = token
        spUtils.put("token", token)
    }

    fun getToken(): String {
        if (token?.isEmpty() == true) {
            val spToken = spUtils.get<String>("token")
            return spToken ?: ""
        } else {
            return token ?: ""
        }
    }

    fun getUserId() :String{
        if (userId?.isEmpty() == true) {
            val spUserId = spUtils.get<String>("userId")
            return spUserId ?: ""
        } else {
            return userId ?: ""
        }
    }

    fun isLogin(): Boolean {
        return getToken().isNotEmpty()
    }

    fun logout() {
        token = ""
        userId = ""
    }
}